﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DnDLib
{
    public class ThreadSafeMethods
    {
        static object lockObj = new Object();

        public static byte[] Splice(byte[] array, int offset, int length)
        {
            lock (lockObj)
            {
                return array.Skip(offset).Take(length).ToArray();
            }
        }

        public static void AddItem<T>(List<T> l, T o)
        {
            lock (lockObj)
            {
                l.Add(o);
            }
        }

        public static void AddRange<T>(List<T> l, IEnumerable<T> o)
        {
            lock (lockObj)
            {
                l.AddRange(o);
            }
        }

        public static void SetAt<T>(List<T> l, int i, T o)
        {
            lock (lockObj)
            {
                l[i] = o;
            }
        }

        public static void Remove<T>(List<T> l, T o)
        {
            lock (lockObj)
            {
                l.Remove(o);
            }
        }

        public static void RemoveAt(IList l, int i)
        {
            lock (lockObj)
            {
                l.RemoveAt(i);
            }
        }

        public static bool Contains<T>(List<T> l, T o)
        {
            lock (lockObj)
            {
                return l.Contains(o);
            }
        }

        public static T GetAt<T>(List<T> l, int i)
        {
            lock (lockObj)
            {
                return l[i];
            }
        }

        public static List<T> GetRange<T>(List<T> l, int index, int count)
        {
            lock (lockObj)
            {
                return l.GetRange(index, count);
            }
        }

        public static int ListCount(IList l)
        {
            lock (lockObj)
            {
                return l.Count;
            }
        }
    }
}
